package com.easylinkin.linkappapi.grid.copy;

import com.easylinkin.core.models.Operator;
import com.easylinkin.linkappapi.grid.entity.GridReportDayDetail;
import com.easylinkin.linkappapi.grid.models.dto.GridReportDayDetailSaveDTO;

/**
 * @author kyj
 * @date 2024/5/21 10:36
 */
public class GridReportDayDetailCopy {
    public static GridReportDayDetail copyAndNew(GridReportDayDetailSaveDTO dto) {

        GridReportDayDetail entity = GridReportDayDetail.builder()
                .reportId(dto.getReportId())
                .gridHierarchy(dto.getGridHierarchy())
                .gridNum(dto.getGridNum())
                .buildGridNum(dto.getBuildGridNum())
                .workerNum(dto.getWorkerNum())
                .dueSafetyOfficerNum(dto.getDueSafetyOfficerNum())
                .actSafetyOfficerNum(dto.getActSafetyOfficerNum())
                .operationTeamNum(dto.getOperationTeamNum())
                .operationCallerNum(dto.getOperationCallerNum())
                .operationCallReferNum(dto.getOperationCallReferNum())
                .checkGeneralHazard(dto.getCheckGeneralHazard())
                .changeGeneralHazard(dto.getChangeGeneralHazard())
                .checkGreatHazard(dto.getCheckGreatHazard())
                .changeGreatHazard(dto.getChangeGreatHazard())
                .personageReportHazard(dto.getPersonageReportHazard())
                .penaltyAmount(dto.getPenaltyAmount())
                .changeInvestmentAmount(dto.getChangeInvestmentAmount())
                .rewardIndividualsAmount(dto.getRewardIndividualsAmount())
                .emergencySituation(dto.getEmergencySituation())
                .build();

        insertCopy(dto.getOperator(), entity);

        return entity;
    }

    public static GridReportDayDetail insertCopy(Operator operator, GridReportDayDetail entity) {
        entity.setTenantId(operator.getTenantId());

        entity.setCreatorId(operator.getUserId());
        entity.setCreator(operator.getUsername());
        entity.setCreateTime(operator.getNow());

        updateCopy(operator, entity);

        return entity;
    }

    public static GridReportDayDetail updateCopy(Operator operator, GridReportDayDetail entity) {
        entity.setModifyId(operator.getUserId());
        entity.setModifier(operator.getUsername());
        entity.setModifyTime(operator.getNow());

        return entity;
    }
}
